package com.wing.cabinet.model.response;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.cabinet.model.entity.Cabinet;
import com.wing.cabinet.model.entity.CabinetCargoSpace;
import com.wing.cabinet.model.entity.StorageInventorySpace;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 收刀柜货位VO
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class CabinetCargoSpaceVO {



    /**
     * ID
     */
    private Long id;

    /**
     * 创建时间
     */
    @JsonFormat(timezone = "GMT+8" , pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime createTime;

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 编号
     */
    private String code;

    /**
     * 货位编号
     */
    private String spaceCode;

    /**
     * 入驻企业ID
     */
    private Long settledCompanyId;

    /**
     * 刀柜ID
     */
    private Long cabinetId;

    /**
     * 产品ID
     */
    private Long productId;

    /**
     * 产品SKU
     */
    private String productSku;

    /**
     * 数量
     */
    private Integer quantity;

    /**
     * 状态
     */
    private CabinetCargoSpace.Status status;

    /**
    * 状态描述
    */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        if (status!=null){
            return status.getDesc();
        }
        return null;
    }

    /**
     * 存入时间
     */
    @JsonFormat(timezone = "GMT+8" , pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime depositTime;


    /**
     * 刀柜自编码
     */
    private String cabCode;


    private Integer quantityInventory;

    private Integer quantityUsable;



    /**
     * sku 名称
     */
    private String skuName;

    /**
     * sku 规格
     */
    private String skuSpec;

    /**
     * sku 图片
     */
    private String skuPic;

    /**
     * 产品名称
     */
    private String productName;

    /**
     * 产品类型名称
     */
    private String productTypeName;

    /**
     * 产品分类名称
     */
    private String productCategoryName;

    /**
     * 产品品牌
     */
    private String productBrandName;



    /**
     * 产品型号
     */
    private String productModelName;

    /**
     * 适配机床
     */
    private String deviceName;

    /**
     * 市场价
     */
    private BigDecimal marketPrice;


    /**
     * 单位
     */
    private String unitName;

    /**
     * 暂存:temp/维修:repair/报废:recycle
     */
    private StorageInventorySpace.BusinessType businessType;


    private String businessTypeCode;

    public String getBusinessTypeCode(){
        if (this.businessType!=null){
            return this.businessType.name();
        }
        return "";
    }

    private String businessTypeDesc;

    public String getBusinessTypeDesc(){
        if (businessType!=null){
            return businessType.getDesc();
        }
        return "";
    }

    private Integer uncheckNum;

    /**
     * 盘验状态,canNotCheck:无,created:待盘验,checked:已盘验;
     */
    private CabinetCargoSpace.CheckStatus checkStatus;

    private String checkStatusDesc;

    public String getCheckStatusDesc(){
        if (checkStatus!=null){
            return checkStatus.getDesc();
        }
        return null;
    }

    /**
     * 刀柜编码
     */
    private String cabinetCode;
    /**
     * 货道状态
     */
    private CabinetCargoSpace.BusinessStatus businessStatus;

    /**
     * 货道状态描述
     */
    @TableField(exist = false)
    private String businessStatusDesc;

    public String getBusinessStatusDesc() {
        if (businessStatus!=null){
            return businessStatus.getDesc();
        }
        return null;
    }

    /**
     * 货道性质
     */
    private CabinetCargoSpace.SpaceNature spaceNature;

    /**
     * 货道性质描述
     */
    @TableField(exist = false)
    private String spaceNatureDesc;

    public String getSpaceNatureDesc() {
        if (spaceNature!=null){
            return spaceNature.getDesc();
        }
        return null;
    }

    /**
     * 权责人
     */
    private String principal;

    /**
     * 入柜产品类型
     */
    private Long spaceProductType;

    private String remark;

    /**
    public CheckStatus getCheckStatus(){
        if (StorageInventorySpace.BusinessType.temp.equals(businessType)){
            if (this.uncheckNum==null||this.uncheckNum==0){
                return CheckStatus.checked;
            }else{
                return CheckStatus.canNotCheck;
            }
        }
        if (this.uncheckNum==null||this.uncheckNum==0){
            return CheckStatus.checked;
        }else if(this.uncheckNum>0){
            return CheckStatus.created;
        }
        return CheckStatus.canNotCheck;
    }*/



    private String brandName;


    private String skuCode;

    private Integer quantityCurrent;

    /**
     * 最大承重
     */
    private String maxBearing;

    /**
     * 最大体积
     */
    private String maxVolume;

    private CabinetCargoSpace.SpaceType spaceType;

    private String spaceTypeDesc;

    public String getSpaceTypeDesc(){
        if (spaceType!=null){
            return spaceType.getDesc();
        }
        return "";
    }

    private String skuCodeTarget;

    private String principalName;

    private String spaceProductTypeName;

    private Long userId;

    private String skuCodeCurrent;

    /**
     * 企业编码
     */
    private String enterpriseCode;

    /**
     * 可存放量
     */
    private Integer storageCapacity;
    private Integer quantityMax;



    public Integer getStorageCapacity(){
        if (this.quantityInventory!=null&&this.quantity!=null){
            return this.quantity-this.quantityInventory;
        }else if(this.quantity!=null){
            return this.quantity;
        }
        return Integer.MAX_VALUE;
    }

    /**
     * 货道当前库存数
     */
    private Integer currentStockCount;

    public Integer getCurrentStockCount(){
        return this.quantityInventory;
    }

    /**
     * 柜子名称
     */
    private String cabName;
    /**
     * 物料数
     */
    private Integer skuQuantity;
    /**
     * 刀柜性质
     */
    private Cabinet.CabinetNature cabinetNature;

    /**
     * 刀柜性质描述
     */
    @TableField(exist = false)
    private String cabinetNatureDesc;

    public String getCabinetNatureDesc() {
        return cabinetNature == null ? null : cabinetNature.getDesc();
    }

    private Integer quantityPack;

    private Integer quantityPackUnit;


    private Long packId;

    private String packName;

    public String getPrincipal(){
        if (StringUtils.isNotBlank(this.principal)){
            if (this.principal.startsWith(",")){
                this.principal=this.principal.substring(1);
            }
            if (this.principal.endsWith(",")){
                this.principal=this.principal.substring(0,this.principal.length()-1);
            }
        }
        return this.principal;
    }

    private String mainCabCode;

    private Boolean alarm;
    private String skuSpecOld;
}
